const fs = require('fs')
const path = require('path')

// 递归遍历 src 目录下的所有 .vue 和 .js 文件
function walkDir(dir, callback) {
    fs.readdirSync(dir).forEach(f => {
        const dirPath = path.join(dir, f)
        const isDirectory = fs.statSync(dirPath).isDirectory()
        isDirectory ? walkDir(dirPath, callback) : callback(dirPath)
    })
}

// 添加 ESLint 忽略注释
function addEslintDisableComment(filePath) {
    let content = fs.readFileSync(filePath, 'utf-8')
    const lines = content.split('\n')

    const newLines = lines.map(line => {
        if (line.includes("import Vue from 'vue'") && !line.includes('eslint-disable-line')) {
            return `${line} // eslint-disable-line no-unused-vars`
        }
        return line
    })

    const newContent = newLines.join('\n')
    if (content !== newContent) {
        fs.writeFileSync(filePath, newContent)
        console.log(`✅ Fixed: ${filePath}`)
    }
}

// 执行修复
walkDir('./src', filePath => {
    if (filePath.endsWith('.js') || filePath.endsWith('.vue')) {
        addEslintDisableComment(filePath)
    }
})
